<template>
  <div>
    <el-form>
      <el-row>
        <el-col :span="6">
          <el-form-item label="名称：">
            <el-input v-model="searchForm.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="上次巡检时间：">
            <el-date-picker
              v-model="patrolTime"
              type="daterange"
              placeholder="选择日期"
              format="YYYY 年 MM 月 DD 日"
              value-format="YYYY-MM-DD"
              >``
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-button style="margin-left: 15px;" type="primary" @click="getLists">搜索</el-button>
          <el-button type="warning" @click="refreshBtn">重置</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
  <div>
    <el-table :data="tableData" border style="width: 100%;">
      <el-table-column prop="point_id" label="ID" width="80"> </el-table-column>
      <el-table-column prop="point_name" label="巡查点名称"> </el-table-column>
      <el-table-column prop="address" label="点位详情"> </el-table-column>
      <el-table-column prop="type_name" label="巡查点类型"> </el-table-column>
      <el-table-column prop="patrol_name" label="巡查人"> </el-table-column>
      <el-table-column prop="last_time" label="上次巡查时间" :formatter="formatterDateTime">
      </el-table-column>
      <el-table-column prop="is_patrol" label="是否按时巡查" :formatter="is_patrolformatterYesNo">
      </el-table-column>
      <el-table-column prop="is_rule" label="是否规则生成的任务" :formatter="formatterYesNo">
      </el-table-column>
      <el-table-column prop="is_pass" label="巡查结果" width="100"> </el-table-column>
      <el-table-column label="操作" fixed="right" width="100">
        <template #default="scope">
          <el-button size="mini" @click="showUnqualifiedDetailInfo(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @current-change="getLists"
        v-model:currentPage="tableDataInfo.page"
        :page-count="tableDataInfo.total_page"
        :total="tableDataInfo.total"
        background
        layout="total,prev, pager, next, jumper"
      >
      </el-pagination>
    </div>
    <el-dialog v-model="patrolPointDetailInfodialogVisible" width="60%">
      <el-scrollbar style="height: 50vh;">
        <patrolPointDetailInfo
          v-if="patrolPointDetailInfodialogVisible"
          :detailInfoObj="detailInfoObj"
        ></patrolPointDetailInfo>
      </el-scrollbar>
    </el-dialog>
  </div>
</template>

<script>
import patrolPointDetailInfo from '@/views/sociolUnitMange/patrolPointDetailInfo.vue'
export default {
  props: ['patrolRecordType', 'patrolRecordTypeDate'],
  components: {
    patrolPointDetailInfo
  },
  data() {
    return {
      tableData: [],
      tableDataInfo: '',
      searchForm: {
        name: '' //点位名称
      },
      patrolTime: '',
      patrolPointDetailInfodialogVisible: false,

      detailInfoObj: ''
    }
  },
  created() {
    this.getLists()
  },
  methods: {
    showUnqualifiedDetailInfo(row) {
      console.log(row)
      this.detailInfoObj = {
        // task_id:row.task_id,
        point_id: row.point_id
      }
      this.patrolPointDetailInfodialogVisible = true
    },
    is_patrolformatterYesNo(row, column, cellValue, index) {
      console.log(cellValue)
      let temp = ['否', '是']
      return temp[cellValue]
    },
    formatterYesNo(row, column, cellValue, index) {
      let temp = ['否', '是']
      return temp[cellValue]
    },
    refreshBtn() {
      this.patrolTime = ''
      let temp = this.searchForm
      for (let key in temp) {
        temp[key] = ''
      }
      this.searchForm = temp
      this.getLists()
    },
    formatterDateTime(row, column, cellValue, index) {
      if (cellValue == null) {
        return ''
      }
      return this.$getDateTime(cellValue)
    },
    getLists(num) {
      let searchData = this.searchForm
      if (this.patrolTime.length) {
        searchData.start_time = this.patrolTime[0]
        searchData.end_time = this.patrolTime[1]
      }
      this.$api
        .post('/unit/UnitDuty/taskPointList', {
          page: num ? num : 1,
          rows: 8,
          list_status: this.patrolRecordType,
          date: this.patrolRecordTypeDate,
          ...searchData
        })
        .then((res) => {
          this.tableData = res.data.list
          delete res.data.list
          this.tableDataInfo = res.data
        })
    }
  }
}
</script>

<style scoped>
.block {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
}
</style>
